import Vue from 'vue'
import Vuet from 'vuet'
import * as request from '../request'
import * as storage from '../storage'

Vue.use(Vuet)
let avatar = require('../assets/images/avatar.png')

export default new Vuet({
  pathJoin: '-',
  modules: {
    // 商品分类列表
    goodsClassifyList: {
      data () {
        return null
      },
      async fetch ({state, route, params, path}) {
        const data = await request.getGoodsClassifyList()
        return data
      }
    },
    tagList: {
      data () {
        return []
      },
      async fetch ({state, route, params, path}) {
        const data = await request.getTagList()
        return data
      }
    },
    // 收货地址列表
    addressList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getAddressList()
        return {requested: true, loading: false, data: response.data}
      }
    },
    // 商店地址列表
    shopAddressList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getShopAddressList()
        return {requested: true, loading: false, data: response}
      }
    },
    // 临时保存的购物车选中的商品id列表，用于请求生成订单（购物车->订单确认 之间的数据传递）
    // selectedCartIdList: {
    //   data () {
    //     return []
    //   },
    //   async fetch() {
    //     return []
    //   }
    // },
    // 用户信息
    memberInfo: {
      data () {
        return storage.getMemberInfo() ||
          {
            member_mobile: '',
            balance: 0,
            integral: 0,
            member_avatar: avatar,
            qrcode_image: '',
            member_name: '',
            member_id: ''
          }
      },
      async fetch() {
        const data = await request.getMemberInfo()
        if (!data.member_avatar || data.member_avatar == '') {
          data.member_avatar = avatar
        }
        storage.setMemberInfo(data)
        return data
      }
    },
    // 退款/退货原因列表
    refundReasonList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getRefundReasonList()
        return data
      }
    },
    // 物流列表
    expressList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getExpressList()
        return data
      }
    },
    // app微信登录的微信信息
    wxInfo: {
      data () {
        return {}
      }
    },
    // 植物属性 载体 基质 场景 健康状态
    plantAttr: {
      data () {
        return {basin: [], dirt: [], environment: [], health: []}
      },
      async fetch() {
        const data = await request.getPlantAttr()
        return data
      }
    },
    // 当前编辑的成长日记对象信息(临时)
    growthNoteTmp: {
      data () {
        return {
          add_time: '', // 添加时间
          behavior: [], // 点亮行为 1浇水 2施肥 3光照 4修剪 5换盆 6日照 7其他
          content: '',  // 内容
          g_id: '', // 花园id
          h_id: '',
          growth_status: '', // 成长状态 0 种子期 1 发芽期 2 幼苗期 3 成株期
          m_id: '', // 百科id
          member_id: '', // 用户id
          o_id: '', // 植物id
          pictures: [], // 图片
          publish_time: '', // 发布时间
          state: '' // 是否删除状态
        }
      }
    },
    // 当前要批量完成的任务id列表（临时）
    taskIdListTmp: {
      data () {
        return []
      }
    },
    // 当前编辑的文章对象信息(临时)
    articleTmp: {
      data () {
        return {
          abstract: '',
          add_time: '',
          content: [],
          id: '',
          d_id: '',
          d_ids: [],
          is_up: '',
          member_avatar: '',
          member_id: '',
          member_name: '',
          read_count: '',
          recommend: '',
          source: '',
          state: '',
          title: '',
          type: '',
          up_count: ''
        }
      }
    },
    // 积分设置 points_money: 积分换算金额数，points_orderrate： 积分最多可抵扣商品价格的比例
    couponSetting: {
      data () {
        return {
          points_money: 0, points_orderrate: 0
        }
      },
      async fetch() {
        const data = await request.getCouponSetting()
        return data
      }
    }
  }
})
